package chixing.day12.class1;

public class TryDemo {
    public static void main(String[] args) {
        try {
            Class.forName("chixing.day07.work.Ab");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        int result = fun2();
        System.out.println(result);
//      CreditAccount account = new CreditAccount();
//      account.setAccBalance(1000);
//      try{
//          account.withdraw(2000);
//          System.out.println("111 try 捕捉异常");
//      }
//      catch (BalanceNotEnoughException e){
//          System.out.println("222 catch 处理异常");
//          System.out.println(e.getMessage());
//      }
//        try{
//            int[] x = {10,20,30};
//            System.out.println(x[5]);
//            String s = null;
//            s.substring(3);
//            int a = 10/0;
//
//        }catch (ArithmeticException e){
//            System.out.println("处理 ArithmeticException异常的代码");
//        }
//        catch (NullPointerException e){
//            System.out.println("处理 NullPointerException异常的代码");
//        }
//        catch (RuntimeException e){
//            System.out.println("处理 RuntimeException");
//        }
//        catch (Exception e){
//            System.out.println("处理 Exception");
//        }
//        fun2();
    }
    //try catch finally
    public static void fun3(){
        try{
            System.out.println("捕捉");
            int a = 10/0;
            System.out.println("处理");
        }catch (Exception e){
            System.out.println("catch 处理");
        }

        finally{ //语法上无论是否有异常，都执行
            //业务上 ：释放资源 如IO流关闭 数据库连接关闭
             System.out.println("finally 处理");
        }
    }
    public static int fun2(){
        int a = 10;
        int b = 2;
        try{
            int c = a/b;
            return 11;
        }
        catch (Exception e){
            System.out.println("catch 处理异常");
            return 12;
        }
        finally{
            System.out.println("finally 处理异常");
        }
    }
}
